/**
 * 
 */
package edu.umd.clip.lm.model.data;

import java.io.IOException;


/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class FilteredReadableTrainingData extends ReadableTrainingData {
	final TrainingDataFilter filter;
	
	/**
	 * @param reader
	 */
	public FilteredReadableTrainingData(TrainingDataReader reader, TrainingDataFilter filter) {
		super(reader);
		this.filter = filter;
	}

	/* (non-Javadoc)
	 * @see java.util.Iterator#next()
	 */
	@Override
	public TrainingDataBlock next() throws IOException {
		TrainingDataBlock block = super.next();
		if (block == null || !block.hasData()) return block;
		TrainingDataBlock newBlock = new TrainingDataBlock(block.size());
		for(ContextFuturesPair pair : block) {
			newBlock.add(filter.filterData(pair));
		}
		return newBlock;
	}
}
